﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Diagnostics;
using System.Data;
using System.Xml.XPath;


namespace WebApp.secure_pages.Xml
{
    public partial class CitizenData : System.Web.UI.Page
    {


        XMLReader reader;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                Response.Redirect("~/Account/Login.aspx");
            }

            //åbner xml filen
            string file_path = "~/secure_pages/Xml/CitizenVitalSignsExampel3_lowercase.xml";
            XDocument xmlDoc = XDocument.Load(Server.MapPath(file_path));

            reader = new XMLReader(xmlDoc);
            setPage();
        }

        private void setPage()
        {
            long patientId = (long) reader.m_Event1.PatientID;

            var db = new F11ITNET2Gr7Entities();
            var user = db.Citizen.Single(u => u.CitizenID == patientId);

            citizenId.Text = user.Name;
            visitation_start.Text = reader.m_StartDate.ToShortDateString();
            visitation_end.Text = reader.m_EndDate.ToShortDateString();

            //event1
            date_data_aquired1.Text = reader.m_Event1.TimeCreated.ToString();

            //oxiometer
            Label_SaturationLevel1.Text = reader.m_Event1.VitalSign.Oximeter.SaturationLevel.ToString();
            Label_HeartRate1_oximeter.Text = reader.m_Event1.VitalSign.Oximeter.HeartRate.ToString();

            //bloodpressure
            Label_diastolic1.Text = reader.m_Event1.VitalSign.BlodPressure.Diastolic.ToString();
            Label_heartrate1_bloodpressure.Text = reader.m_Event1.VitalSign.BlodPressure.HartRate.ToString();
            Label_systolic1.Text = reader.m_Event1.VitalSign.BlodPressure.Systolic.ToString();

            //weight
            Label_weigth1.Text = (reader.m_Event1.VitalSign.Weigth.WeightInGrams / 1000).ToString(); ;


            //event2
            date_data_aquired2.Text = reader.m_Event2.TimeCreated.ToString();

            //oxiometer
            Label_SaturationLevel2.Text = reader.m_Event2.VitalSign.Oximeter.SaturationLevel.ToString();
            Label_HeartRate2_oximeter.Text = reader.m_Event2.VitalSign.Oximeter.HeartRate.ToString();

            //bloodpressure
            Label_diastolic2.Text = reader.m_Event2.VitalSign.BlodPressure.Diastolic.ToString();
            Label_heartrate2_bloodpressure.Text = reader.m_Event2.VitalSign.BlodPressure.HartRate.ToString();
            Label_systolic2.Text = reader.m_Event2.VitalSign.BlodPressure.Systolic.ToString();

            //weight - er tom
            //Label_weigth2.Text = (reader.m_Event2.VitalSign.Weigth.WeightInGrams / 100).ToString();
                
        }

        
       
    }

   
}